//
//  main.c
//  client
//
//  Created by  AbbyCin on 10/28/14.
//  Copyright (c) 2014  AbbyCin. All rights reserved.
//

#include "Header.h"
#include "sock_act.h"

void err(char *fun)
{
    perror(fun);
    exit(1);
}
int main(int argc, const char * argv[])
{
    if(argc < 3)
    {
        printf("%s ipaddr command\n",argv[0]);
        exit(1);
    }
    
    if(strlen(argv[2]) > cmd_len)
	{
		printf("command is too long\n");
		exit(1);
	}
    int sfd = 0;
    int status = 0;
    
    sfd = Connect(argv[1], "30920", SOCK_STREAM);
    if(sfd == -1)
        err("Connect");

    write(sfd, argv[2], strlen(argv[2])); 	/* write command */
    shutdown(sfd,SHUT_WR);
    
    read(sfd,&status,sizeof(status));
    printf("Server exit code: %d\n",status);
    close(sfd);

    return 0;
}